package com.tjsinfo.tjsoa.documentationflow.xingzhengshouwen.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Disjunction;
import org.hibernate.criterion.Restrictions;
import org.json.JSONArray;
import org.json.JSONObject;

import com.tjsinfo.tjsoa.common.SessionUser;
import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.bo.ITXingzhengfawenNeirongBO;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.FaWenInfo;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.TXingzhengfawenNeirong;
import com.tjsinfo.tjsoa.documentationflow.xingzhengshouwen.bo.ITXingzhengshouwenNeirongBO;
import com.tjsinfo.tjsoa.documentationflow.xingzhengshouwen.vo.ShouWenInfo;
import com.tjsinfo.tjsoa.system.bo.IDepartmentBo;
import com.tjsinfo.tjsoa.system.bo.ISystemUserBo;
import com.tjsinfo.tjsoa.system.bo.ISystemUserDepartmentBo;
import com.tjsinfo.tjsoa.system.vo.TSystemDepartment;
import com.tjsinfo.tjsoa.system.vo.TSystemUserDepartment;
import com.tjsinfo.tjsoa.workflow.WorkFlowTemplate;
import com.tjsinfo.tjsoa.workflow.bo.ITaskInstanceBO;

/**
 * 查阅文件
 * @author Administrator
 *
 */
public class ChaYueWenJianAction extends Action{
	private ITXingzhengshouwenNeirongBO xingzhengshouwenNeirongBO;
	
	

	public ITXingzhengshouwenNeirongBO getXingzhengshouwenNeirongBO() {
		return xingzhengshouwenNeirongBO;
	}



	public void setXingzhengshouwenNeirongBO(
			ITXingzhengshouwenNeirongBO xingzhengshouwenNeirongBO) {
		this.xingzhengshouwenNeirongBO = xingzhengshouwenNeirongBO;
	}



	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		Boolean isZhiShu = false;
		Integer first =  0;
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		String path = request.getContextPath();
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
		String tablename = request.getParameter("tablename");
		String start = request.getParameter("start");
		String limit = request.getParameter("limit");
		String subtype = request.getParameter("subtype");
		if(tablename==null){
			tablename="xingzhengshouwen";
		}
		if("all".equals(subtype)||subtype==null){
			subtype=null;
		}else{
			subtype="行"+subtype+"字";
		}
		String laiwenjiguan = request.getParameter("laiwenjiguan");
		String laiwenzihao = request.getParameter("laiwenzihao");
		String zhaiyou = request.getParameter("laiwenbiaoti");
		List<ShouWenInfo> faWenInfoList = new ArrayList<ShouWenInfo>();
		JSONArray array = new JSONArray();
		JSONObject object = new JSONObject();
		if (request.getParameter("start") == null) {
			faWenInfoList = xingzhengshouwenNeirongBO.selectChaYueWenJian(SessionUser.getUserId(request), 0, (0 + 23), laiwenjiguan, laiwenzihao, zhaiyou,tablename,subtype);

		} else {
			 first = Integer.parseInt(request.getParameter("start"));
			faWenInfoList =  xingzhengshouwenNeirongBO.selectChaYueWenJian(SessionUser.getUserId(request), (first + 1), (first + 23) , laiwenjiguan, laiwenzihao, zhaiyou,tablename,subtype);

			
		}
		
		Integer totalProperty = xingzhengshouwenNeirongBO.selectChaYueWenJianCount(SessionUser.getUserId(request), 0, (0 + 23), laiwenjiguan, laiwenzihao, zhaiyou,tablename,subtype);		
		object.put("totalProperty", totalProperty);
		for (ShouWenInfo faWenInfo : faWenInfoList) {
			if(faWenInfo.getId() != null){
				JSONObject object2 = new JSONObject(faWenInfo);
				if ("xingzhengshouwen".equals(faWenInfo.getTableName())) {
					object2.put("operate", "<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=selectonedoc&id="+faWenInfo.getId()+"'>查看</a>");
				}else if ("dangweishouwen".equals(faWenInfo.getTableName())) {
					object2.put("operate", "<a href='"+basePath+"tjsinfo/tjsoa/dangweishouwen/shenpi.do?method=selectonedoc&id="+faWenInfo.getId()+"'>查看</a>");
				}
				
				array.put(object2);
			}
			
		}
		object.put("root", array);
		response.getWriter().print(object);
		return null;
	}
	
}

